package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.mapper.DictionaryItemMapper;
import cn.wolfcode.crm.mapper.DictionaryMapper;
import cn.wolfcode.crm.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryServiceImpl implements IDictionaryService {
    @Autowired
    private DictionaryMapper dictionaryMapper;
    @Autowired
    private DictionaryItemMapper dictionaryItemMapper;


    public void insert(Dictionary record) {
        dictionaryMapper.insert(record);
    }

    public void updateByPrimaryKey(Dictionary record) {
        dictionaryMapper.updateByPrimaryKey(record);
    }

    public List<Dictionary> selectAll() {
        return dictionaryMapper.selectAll();
    }

    public void deleteByPrimaryKey(Long id) {
        dictionaryItemMapper.deleteByDictionaryName(dictionaryMapper.selectByPrimaryKey(id).getName());
        dictionaryMapper.deleteByPrimaryKey(id);
    }

    public List<Dictionary> selectDictionaryByName(String name) {
        List<Dictionary> list =  dictionaryMapper.selectDictionaryByName(name);
        return list;
    }


}
